local zong__feiren = fk.CreateSkill{
  name = "zong__feiren",
}

Fk:loadTranslationTable{
  ["zong__feiren"] = "飞人",
  [":zong__feiren"] = "出牌阶段限一次，你可以弃置两张手牌并摸三张牌，然后本阶段你使用的下一张【杀】无距离与次数限制且视为火【杀】。",
  ["#zong__feiren-active"] = "飞人：你可以弃置两张手牌并摸三张牌，然后本阶段你使用的下一张【杀】无距离与次数限制且视为火【杀】。",
}

zong__feiren:addEffect("active", {
  prompt = "#zong__feiren-active",
  max_phase_use_time = 1,
  phase = "play",

  card_num = function(self, player)
    return math.min(player:getHandcardNum(), 2)
  end,

  card_filter = function(self, player, to_select, selected)
    local need_num = self:card_num(player)
    return #selected < need_num
      and table.contains(player:getCardIds("h"), to_select)
      and not player:prohibitDiscard(to_select)
  end,

  on_use = function(self, room, effect)
    local player = effect.from  
    room:notifySkillInvoked(player, "zong__feiren")

    if #effect.cards > 0 then
      room:throwCard(effect.cards, self.name, player, player) 
    end

    room:drawCards(player, 3, self.name)

    room:setPlayerMark(player, "zong__feiren_effect", 1)

    return false
  end,
})

zong__feiren:addEffect(fk.AfterCardUseDeclared, {
  can_trigger = function(self, event, target, player, data)
    return target == player 
      and player:getMark("zong__feiren_effect") > 0
      and data.card.trueName == "slash"  
  end,

  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)

    data:changeCard("fire__slash", data.card.suit, data.card.number, zong__feiren.name)
    local room = player.room
    room:setPlayerMark(player, "zong__feiren_effect", 0)
  end,
})

zong__feiren:addEffect("targetmod", {

  bypass_times = function(self, player, skill, scope, card)
    return card and card.trueName == "slash"  
      and player:getMark("zong__feiren_effect") > 0  
  end,

  bypass_distances = function(self, player, skill, card)
    return card and card.trueName == "slash"  
      and player:getMark("zong__feiren_effect") > 0  
  end,
})

zong__feiren:addEffect(fk.EventPhaseEnd, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(zong__feiren.name)
      and data.phase == Player.Play
      and player:getMark("zong__feiren_effect") > 0
  end,

  on_cost = Util.TrueFunc,

  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "zong__feiren_effect", 0)
  end,
})

return zong__feiren